package com.example.etwzgzxt.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.etwzgzxt.R;
import com.example.etwzgzxt.bean.MessageInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 创宇 on 2016/1/26.
 */
public class MessageListAdapter extends BaseAdapter {


    private List<MessageInfo> items = new ArrayList<>();
    private LayoutInflater inflater;

    public MessageListAdapter(Context context, List<MessageInfo> items) {
        this.inflater = inflater.from(context);
        this.items.addAll(items);
    }

    public void updateData(List<MessageInfo> items) {
        this.items.clear();
        this.items.addAll(items);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public Object getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return new Long(items.get(position).getMessageid());
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        view = inflater.inflate(R.layout.item_message_list, null);
        ((TextView) view.findViewById(R.id.tvId)).setText((position+1)+"");
        ((TextView) view.findViewById(R.id.tvlat)).setText(items.get(position).getLatitude());
        ((TextView) view.findViewById(R.id.tvhappendtime)).setText(items.get(position).getHappendtime());
        ((TextView) view.findViewById(R.id.tvlon)).setText(items.get(position).getLongtitude());
        return view;
    }
}
